package com.maimang.platform.crm.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * @author Rocky
 * @version 1.0.0
 * @classname MyCommandRunner
 * @description <br>使用命令行调用浏览器打开应用</br>
 * @date 2019-07-24 14:32
 * @email jintaozhao@qq.com
 */
@Component
public class MyCommandRunner implements CommandLineRunner {

	private static Logger logger = LoggerFactory.getLogger(MyCommandRunner.class);
	@Value("${spring.web.openurl}")
	private String openUrl;

	@Value("${spring.web.browser}")
	private String browserPath;

	@Value("${spring.auto.open}")
	private boolean isOpen;

	@Override
	public void run(String... args) {
		if (isOpen) {
			String cmd = browserPath + " " + openUrl;
			Runtime run = Runtime.getRuntime();
			try {
				run.exec(cmd);
				logger.debug("启动浏览器打开项目成功");
			} catch (Exception e) {
				e.printStackTrace();
				logger.error(e.getMessage());
			}
		}
	}
}
